﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市管理系统</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <style>
        button {
            padding: 7px 30px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #45a049;
        }

        button:active {
            background-color: #3e8e41;
        }

        .radio-group {
            display: inline-flex;
        }
        
        .radio-group label {
            margin-right: 10px;
        }

        #a1 {
            margin: 0 150px;
        }
    </style>
</head>
<body>
<!--头部-->
<header class="publicHeader">
    <h1>超市管理系统</h1>

    <div class="publicHeaderR">
        <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
        <a href="logout">退出</a>
    </div>
</header>
<!--时间-->
<section class="publicTime">
    <span id="time">2020年1月1日 11:11  星期一</span>
    <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
</section>
<!--主体内容-->
<section class="publicMian ">
    <div class="left">
        <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
        <nav>
            <ul class="list">
                <li id="active"><a href="billList.html">账单管理</a></li>
                <li><a href="providerList.html">物品管理</a></li>
                <li><a href="userList.html">用户管理</a></li>
                <!-- <li><a href="password.html">密码修改</a></li> -->
                <li><a href="logout">退出系统</a></li>
            </ul>
        </nav>
    </div>
    <div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>账单管理页面 >> 订单添加页面</span>
        </div>
        <div class="providerAdd">
            <form action="#" method="post">
                <!--div的class 为error是验证错误，ok是验证成功-->
                <div class="">
                    <label for="name">姓名：</label>
                    <input type="text" name="name" id="name" required/>
                    <span>*请输入姓名</span>
                </div>
                <div>
                    <label for="address">地址：</label>
                    <input type="text" name="address" id="address" required/>
                    <span >*请输入地址</span>
                </div>
                <div>
                    <label for="mail">邮箱：</label>
                    <input type="text" name="mail" id="mail" required/>
                    <span>*请输入邮箱</span>

                </div>
                <div>
                    <label for="phone">电话：</label>
                    <input type="text" name="phone" id="phone" required/>
                    <span>*请输入电话</span>
                </div>
                <div>
                    <label for="note">备注：</label>
                    <input type="text" name="note" id="note" required/>
                </div>
                    <!-- <label for="payment">支付方式：</label>
                    <input type="text" name="payment" id="payment" required/> -->
                    <table id="a1">
                        <td>支付方式：</td>
                        <tr>
                            <td><input id="r1" type="radio" name="payment" value="0" checked/>货到付款</td>
                            <td><input id="r2" type="radio" name="payment" value="1"/>余额支付</td>
                            <td><input id="r3" type="radio" name="payment" value="2"/>支付宝</td>
                            <td><input id="r4" type="radio" name="payment" value="3"/>微信</td>
                        </tr>
                    </table>
                <div>
                </div>
                <div>
                    <!-- <label for="delivery">配送方式：</label>
                    <input type="text" name="delivery" id="delivery" required/> -->
                    <table id="a1">
                        <td>配送方式：</td>
                        <tr>
                            <td><input id="f1" type="radio" name="delivery" value="0" checked/>顺丰快递</td>
				            <td><input id="f2" type="radio"  name="delivery" value="1"/>韵达快递</td>
                        </tr>
                    </table>
                </div>
                <div class="providerAddBtn">
                    <!--<a href="#">保存</a>-->
                    <!--<a href="billList.html">返回</a>-->
                    <button>保存</button>
                    <input type="button" value="返回" onclick="history.back(-1)"/>
                </div>
            </form>
        </div>

    </div>
</section>
<footer class="footer">
</footer>
<script src="js/time.js"></script>
<script src="js/axios.min.js"></script>
<script>
    document.querySelector('form').addEventListener('submit', function(e){
        e.preventDefault();

        const name = document.getElementById('name').value;
        const address = document.getElementById('address').value;
        const mail = document.getElementById('mail').value;
        const phone = document.getElementById('phone').value;
        const note = document.getElementById('note').value;

        var payment = 0
        var delivery = 0
        // 获取单选按钮的引用
        var radio1 = document.getElementById("r1");
        var radio2 = document.getElementById("r2");
        var radio3 = document.getElementById("r3");
        var radio4 = document.getElementById("r4");

        var f1 = document.getElementById("f1");
        var f2 = document.getElementById("f2");

        if(f1.checked){
            delivery = 0
        }else if(f2.checked){
            delivery = 1
        }

        // 检查单选按钮是否被选中
        if (radio1.checked) {
        // 单选按钮1被选中payment
        payment = 0
        } else if (radio2.checked) {
            payment = 1
        } else if (radio3.checked) {
            payment = 2
        } else if (radio4.checked) {
            payment = 3
        } else {
            payment = 0
        }

        axios({
            url: 'pur',
            method: 'POST',
            data: {
                name,
                address,
                mail,
                phone,
                note,
                payment,
                delivery
            }
        }).then(result => {
            if(result.data.code === 1){
                alert(result.data.data);
                location.href='billList.html';
            } else{
                alert(result.data.data);
            }
        });
    });
</script>

</body>
</html>